/**
 * edurender
 * ersw_context.h
 * (c) 2009 J. Brad Byrd
 */

#ifndef ERSW_CONTEXT_H
#define ERSW_CONTEXT_H

#include "ersw_types.h"
#include "ersw_texture.h"

#include "../er/er_hashtable.h"

#include <limits.h>

typedef enum ERSWResource
{
	ERSW_RESOURCE_TEXTURE2D,
	
	ERSW_MAX_RESOURCE,
} ERSWResource;

typedef struct ERSWContext
{
	void *window;
	ERHashTable *resourceTables[ERSW_MAX_RESOURCE];
	ERuint nextHandle;
	ERbool depthEnable;
	ERbool depthMask;
	ERFrontFace frontFace;
	ERCullFace cullFace;
	ERMatrix4x4f modelview;
	ERMatrix4x4f projection;
	ERSWViewport viewport;
	ERSWTexture2D *texture;
 	ERSWFramebuffer framebuffer;
 	const ERfloat *posArray;
 	const ERfloat *texCoordArray[2];
 	ERuint posStride;
	ERuint texCoordStride[2];
	ERSWInputVertex inputVerts[USHRT_MAX];
	ERSWOutputVertex outputVerts[USHRT_MAX];
	struct ERSWContext *next;
} ERSWContext;

ERSWContext *erswCreateContext(ERushort width, ERushort height, void *window);
void erswDestroyContext(ERSWContext *context);
void erswDestroyAllContexts();
ERHandle erswContextAddResource(ERSWContext *context, ERSWResource type, void *data);
void *erswContextFindResource(ERSWContext *context, ERSWResource type, ERHandle handle);
void erswContextRemoveResource(ERSWContext *context, ERSWResource type, ERHandle handle);
ERResult erswSwapBuffers(ERSWContext *context);

#endif // ERSW_CONTEXT_H
